/*
 * @lc app=leetcode.cn id=409 lang=csharp
 *
 * [409] 最长回文串
 */

// @lc code=start
public class Solution {
    public int LongestPalindrome(string s) {
        int[] lens = new int[52];
        char gapChar = (char) ('Z' + 1);
        
        for(int i = 0; i < s.Length; ++i)
        {
            char c = s[i];
            int ix =  ( c > gapChar ? 26 + c - 'a' : c - 'A');
            lens[ix] = lens[ix] + 1;
        }
        
        int ans = 0;
        bool hasOdd = false;
        
        for(int i = 0; i < lens.Length; ++i)
        {
            int num = lens[i];
            if(num % 2 == 0)
                ans += num;
            else
            {
                ans += num - 1;
                hasOdd = true;
            }
        }
        return hasOdd ? ans + 1 : ans;
    }
}
// @lc code=end

